using System;
using System.Collections.Generic;
using System.Text;

namespace Midas.Core
{
	public static class MidasLogManager
	{
		public static event StringHandler LoggingEvent;

		private static int debugLevel = 5;

		public static int DebugLevel
		{
			get { return MidasLogManager.debugLevel; }
			set { MidasLogManager.debugLevel = value; }
		}
		
		public static void RegisterListeners(string listeners)
		{
			string[] parts = listeners.Split(';');
			foreach (string s in parts)
			{
				string st = s.Trim();
				if (st.Equals("{console}"))
				{
					LoggingEvent += MidasConsoleListener.LogEvent;
					continue;
				}
				st.Replace("{date}", DateTime.Now.ToString("yyyy-MM-dd"));
				try
				{
					LoggingEvent += new MidasFileListener(st).LogEvent;
				}
				catch (Exception) { }
			}
		}

		public static void LogEvent(string s, int level)
		{
			if(level<=debugLevel)
				try
				{
					LoggingEvent(s);
				}
				catch (Exception)
				{
				}
		}
	}
}
